package com.woniuxy.qiantai.config;

import com.woniuxy.qiantai.interceptors.JwtRenewInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration  //指明当前类是配置类
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    JwtRenewInterceptor jwtRenewInterceptor;


    //registry  注册表
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //WebMvcConfigurer.super.addViewControllers(registry);

        //注册 路径和视图的匹配关系
        registry.addViewController("/").setViewName("homeh");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/register.html").setViewName("register");
        registry.addViewController("/mycart.html").setViewName("mycart");
        registry.addViewController("/myOrder.html").setViewName("myOrder");
        registry.addViewController("/allShop.html").setViewName("allShop");
        registry.addViewController("/selectShopByType.html").setViewName("selectShopByType");
        registry.addViewController("/work3.html").setViewName("work3");
        registry.addViewController("/homeh.html").setViewName("homeh");
        registry.addViewController("/homev.html").setViewName("homev");
        registry.addViewController("/businessDetails.html").setViewName("businessDetails");

        //范启文 测试页面：
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/register.html").setViewName("register");
        //范启文：跳转到我的购物车页面
        registry.addViewController("/mycart.html").setViewName("mycart");
        //范启文：跳转到预览订单页面
        registry.addViewController("/orderPreview.html").setViewName("orderPreview");
        //范启文：跳转到订单页面
        registry.addViewController("/order.html").setViewName("order");

        //张朝朝：跳转到order测试页面
        // registry.addViewController("/order.html").setViewName("order");
    }



    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> exclude = new ArrayList<>();

        exclude.add("/**/*login*/**");

        exclude.add("/**/*user*/**");

        exclude.add("/**/*register*/**");

        exclude.add("/**/*success*/**");

        exclude.add("/**/*error*/**");

        exclude.add("/**/*.png");

        exclude.add("/**/*.js");

        exclude.add("/**/*.css");

        exclude.add("/**/*.jpg");

        registry.addInterceptor(jwtRenewInterceptor).addPathPatterns("/**").excludePathPatterns(exclude);
        //registry.addInterceptor(loginInterceptor()).addPathPatterns("/**").excludePathPatterns(exclude);


    }

}
